package com.ymatou.iapi.trading.operate.testcase;

import java.util.HashMap;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.SyncIdCardInfoBean;
import com.ymatou.iapi.trading.operate.service.SyncIdCardInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.sqlwapper.DefaultWapper;
/**
*身份证信息同步
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SyncIdCardInfo {
	private static SyncIdCardInfoBean syncidcardinfoBean;
	private static SyncIdCardInfoCall syncidcardinfoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("身份证信息同步");
	}

	@Before
	public void caseUp() {
		syncidcardinfoBean = new SyncIdCardInfoBean();
		syncidcardinfoCall = new SyncIdCardInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(syncidcardinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SyncIdCardInfo_001() {
		Logger.start(true, "身份证验证信息同步成功");
		try {
			syncidcardinfoBean.setBuyerId(4085);
			syncidcardinfoBean.setIsUploaded(1);
			syncidcardinfoBean.setName("王五");

			syncidcardinfoCall.setData(syncidcardinfoBean);
			syncidcardinfoCall.callService();

			Logger.verifyEquals("ok", syncidcardinfoCall.getReturnData(),
					"验证Code");

			//数据库验证
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Object> m = new HashMap<String, Object>();
			m.put("Name", syncidcardinfoBean.getName());
			m.put("BuyerId", syncidcardinfoBean.getBuyerId());

			Logger.verifyEquals(
					true,
					database.selectOrderExtByBuyerIdAndName(m).get(0)
							.get("bHaveUploadedIdCard"), "验证身份证同步状态");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SyncIdCardInfo_002() {
		Logger.start(false, "身份证用户名为空,验证失败");
		try {
			syncidcardinfoBean.setBuyerId(4085);
			syncidcardinfoBean.setIsUploaded(1);

			syncidcardinfoCall.setData(syncidcardinfoBean);
			syncidcardinfoCall.callService();

			//Logger.verifyEquals("fail", syncidcardinfoCall.getMsg(), "验证Msg");
			Logger.verifyEquals("fail", syncidcardinfoCall.getReturnData(),
					"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SyncIdCardInfo_003() {
		Logger.start(false, "用户ID为空,验证失败");
		try {
			syncidcardinfoBean.setIsUploaded(1);
			syncidcardinfoBean.setName("巴巴");

			syncidcardinfoCall.setData(syncidcardinfoBean);
			syncidcardinfoCall.callService();

			Logger.verifyEquals("fail", syncidcardinfoCall.getReturnData(),
					"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}